package com.swd.order.util;


import net.coobird.thumbnailator.Thumbnails;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import javax.imageio.ImageIO;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;

@RunWith(SpringRunner.class)
@SpringBootTest
public class ImgUtil {


    public static void compression(byte[] imgByte,int width,int height,String filePath) throws IOException {
        Thumbnails.of(ImageIO.read(new ByteArrayInputStream(imgByte))).size(width,height).toFile(new File(filePath));
    }

    public static void compression(File file,int width,int height,String filePath) throws IOException {
        Thumbnails.of(file).size(width,height).toFile(new File(filePath));
    }

    public static void compression(String file,int width,int height,String filePath) throws IOException {
        Thumbnails.of(new File(file)).size(width,height).toFile(new File(filePath));
    }

    public static void clearImage(String filePath){
        File file = new File(filePath);
        File absoluteFile = file.getAbsoluteFile();
        System.out.println(absoluteFile);
    }
}
